/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						script_targeted_expression.h

	$Header: /heroes4/script_targeted_expression.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( SCRIPT_TARGETED_EXPRESSION_H_INCLUDED )
#define SCRIPT_TARGETED_EXPRESSION_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "abstract_script_expression.h"
#include "read_script_target_from_map.h"
#include "script_target_type.h"

// --------------------------------------------------------------------------
// t_script_targeted_expression class template
// --------------------------------------------------------------------------

template < typename t_base, typename t_target_arg >
class t_script_targeted_expression : public t_base
{
public:
	// Types
	typedef t_target_arg	t_target;

	// Constructor
	t_script_targeted_expression();

	// Member functions
	t_target		get_target() const;

	virtual bool	read( std::streambuf& stream, int version );
	virtual bool	read_from_map(
						std::streambuf &	stream,
						int					format_version );
	virtual bool	write( std::streambuf& stream ) const;

private:
	// Data members
	t_target	m_target;
};

// --------------------------------------------------------------------------
// t_script_targeted_expression members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_base, typename t_target_arg >
inline t_script_targeted_expression< t_base, t_target_arg >::t_script_targeted_expression()
	:	m_target( t_target( 0 ) )
{
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_base, typename t_target_arg >
inline typename t_script_targeted_expression< t_base, t_target_arg >::t_target
t_script_targeted_expression< t_base, t_target_arg >::get_target() const
{
	return m_target;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_base, typename t_target_arg >
bool t_script_targeted_expression< t_base, t_target_arg >::read_from_map(
	std::streambuf &	stream,
	int					format_version )
{
	return read_script_target_from_map( stream, format_version, m_target );
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_base, typename t_target_arg >
bool t_script_targeted_expression< t_base, t_target_arg >::read(std::streambuf& stream, int version)
{
	m_target = get< t_target_arg >( stream );
	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_base, typename t_target_arg >
bool t_script_targeted_expression< t_base, t_target_arg >::write(std::streambuf& stream) const
{
	if (!t_base::write( stream ))
		return false;
	put< t_target_arg >( stream, m_target );
	return true;
}

// --------------------------------------------------------------------------
// t_script_targeted_boolean_expression class template
// --------------------------------------------------------------------------

template < typename t_target_arg >
class t_script_targeted_boolean_expression
	:	public	t_script_targeted_expression<
					t_abstract_script_boolean_expression,
					t_target_arg >
{
};

// --------------------------------------------------------------------------
// t_script_targeted_numeric_expression class template
// --------------------------------------------------------------------------

template < typename t_target_arg >
class t_script_targeted_numeric_expression
	:	public	t_script_targeted_expression<
					t_abstract_script_numeric_expression,
					t_target_arg >
{
};

#endif // !defined( SCRIPT_TARGETED_EXPRESSION_H_INCLUDED )
